"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var hardware_model_1 = require("./hardware-model");
var BatteryLevel;
(function (BatteryLevel) {
    BatteryLevel[BatteryLevel["unknown"] = 0] = "unknown";
    BatteryLevel[BatteryLevel["low"] = 1] = "low";
    BatteryLevel[BatteryLevel["one"] = 2] = "one";
    BatteryLevel[BatteryLevel["two"] = 3] = "two";
    BatteryLevel[BatteryLevel["three"] = 4] = "three";
    BatteryLevel[BatteryLevel["four"] = 5] = "four";
    BatteryLevel[BatteryLevel["low_charge"] = 6] = "low_charge";
    BatteryLevel[BatteryLevel["one_charge"] = 7] = "one_charge";
    BatteryLevel[BatteryLevel["two_charge"] = 8] = "two_charge";
    BatteryLevel[BatteryLevel["three_charge"] = 9] = "three_charge";
    BatteryLevel[BatteryLevel["four_charge"] = 10] = "four_charge";
})(BatteryLevel = exports.BatteryLevel || (exports.BatteryLevel = {}));
var BatteryService = /** @class */ (function () {
    function BatteryService() {
    }
    BatteryService.level = function (batteryValue, chargingValue) {
        var isCharging = (chargingValue == "1" || chargingValue == "true");
        if (isCharging) {
            if (batteryValue == "0") {
                return BatteryLevel.low_charge;
            }
            else if (batteryValue == "1") {
                return BatteryLevel.low_charge;
            }
            else if (batteryValue == "2") {
                return BatteryLevel.one_charge;
            }
            else if (batteryValue == "3") {
                return BatteryLevel.two_charge;
            }
            else if (batteryValue == "4") {
                return BatteryLevel.three_charge;
            }
            else if (batteryValue == "5") {
                return BatteryLevel.four_charge;
            }
            else {
                return BatteryLevel.unknown;
            }
        }
        if (batteryValue == "0") {
            return BatteryLevel.low;
        }
        else if (batteryValue == "1") {
            return BatteryLevel.one;
        }
        else if (batteryValue == "2") {
            return BatteryLevel.two;
        }
        else if (batteryValue == "3") {
            return BatteryLevel.three;
        }
        else if (batteryValue == "4") {
            return BatteryLevel.four;
        }
        else if (batteryValue == "5") {
            return BatteryLevel.four;
        }
        else {
            return BatteryLevel.unknown;
        }
    };
    BatteryService.image = function (level) {
        switch (level) {
            case BatteryLevel.low: {
                return "icon_battery6.png";
            }
            case BatteryLevel.one: {
                return "icon_battery4.png";
            }
            case BatteryLevel.two: {
                return "icon_battery3.png";
            }
            case BatteryLevel.three: {
                return "icon_battery2.png";
            }
            case BatteryLevel.four: {
                return "icon_battery1.png";
            }
            case BatteryLevel.low_charge: {
                return "icon_battery01.gif";
            }
            case BatteryLevel.one_charge: {
                return "icon_battery12.gif";
            }
            case BatteryLevel.two_charge: {
                return "icon_battery23.gif";
            }
            case BatteryLevel.three_charge: {
                return "icon_battery34.gif";
            }
            case BatteryLevel.four_charge: {
                return "icon_battery11.png";
            }
            default: {
                return "icon_battery6.png";
            }
        }
    };
    return BatteryService;
}());
exports.BatteryService = BatteryService;
var PmLevel;
(function (PmLevel) {
    PmLevel[PmLevel["unknown"] = 0] = "unknown";
    PmLevel[PmLevel["one"] = 1] = "one";
    PmLevel[PmLevel["two"] = 2] = "two";
    PmLevel[PmLevel["three"] = 3] = "three";
    /*four,            //150-200   中度污染
    five,            //200-300   重度污染
    six              //300-500   严重污染*/
})(PmLevel = exports.PmLevel || (exports.PmLevel = {}));
//pm: 35-75
var PmService = /** @class */ (function () {
    function PmService() {
    }
    PmService.level = function (pmValue) {
        var pmInt = parseInt(pmValue);
        if (isNaN(pmInt) || pmInt < 0) {
            return PmLevel.unknown;
        }
        if (pmInt == 0xffff) {
            return PmLevel.one;
        }
        if (pmInt < 35) {
            return PmLevel.one;
        }
        else if (pmInt < 75) {
            return PmLevel.two;
        }
        else {
            return PmLevel.three;
        }
    };
    PmService.offlineClass = function (level) {
        switch (level) {
            case PmLevel.one: {
                return "cube-blue-offline";
            }
            case PmLevel.two: {
                return "cube-yellow-offline";
            }
            case PmLevel.three: {
                return "cube-red-offline";
            }
            /*case PmLevel.four: {
              return "cube-red-offline"
            }
            case PmLevel.five: {
              return "cube-red-offline"
            }
            case PmLevel.six: {
              return "cube-red-offline"
            }*/
            default: {
                return "cube-unknown-offline";
            }
        }
    };
    PmService.bgColorClass = function (level) {
        switch (level) {
            case PmLevel.one: {
                return "cube-blue";
            }
            case PmLevel.two: {
                return "cube-yellow";
            }
            case PmLevel.three: {
                return "cube-red";
            }
            /*case PmLevel.four: {
              return "cube-red"
            }
            case PmLevel.five: {
              return "cube-red"
            }
            case PmLevel.six: {
              return "cube-red"
            }*/
            default: {
                return "cube-unknown";
            }
        }
    };
    PmService.title = function (level) {
        switch (level) {
            case PmLevel.one: {
                return "REFERENCE.GOOD";
            }
            case PmLevel.two: {
                return "REFERENCE.MODERATE";
            }
            case PmLevel.three: {
                return "REFERENCE.UNHEALTHY";
            }
            default: {
                return "REFERENCE.UNABLE_TO_OBTAIN_DATA";
            }
        }
    };
    return PmService;
}());
exports.PmService = PmService;
var HchoLevel;
(function (HchoLevel) {
    HchoLevel[HchoLevel["unknown"] = 0] = "unknown";
    HchoLevel[HchoLevel["normal"] = 1] = "normal";
    HchoLevel[HchoLevel["over"] = 2] = "over";
    HchoLevel[HchoLevel["serious"] = 3] = "serious";
})(HchoLevel = exports.HchoLevel || (exports.HchoLevel = {}));
var HchoService = /** @class */ (function () {
    function HchoService() {
    }
    HchoService.level = function (hchoValue) {
        var hchoFloat = parseFloat((parseInt(hchoValue) / 1000).toFixed(2));
        if (isNaN(hchoFloat) || parseInt(hchoValue) < 0) {
            return HchoLevel.unknown;
        }
        if (parseInt(hchoValue) == 0xffff) {
            return HchoLevel.normal;
        }
        if (hchoFloat < 0.08) {
            return HchoLevel.normal;
        }
        else if (hchoFloat < 0.10) {
            return HchoLevel.over;
        }
        else {
            return HchoLevel.serious;
        }
    };
    HchoService.offlineClass = function (level) {
        switch (level) {
            case HchoLevel.normal: {
                return "cube-blue-offline";
            }
            case HchoLevel.over: {
                return "cube-yellow-offline";
            }
            case HchoLevel.serious: {
                return "cube-red-offline";
            }
            default: {
                return "cube-unknown-offline";
            }
        }
    };
    HchoService.bgColorClass = function (level) {
        switch (level) {
            case HchoLevel.normal: {
                return "cube-blue";
            }
            case HchoLevel.over: {
                return "cube-yellow";
            }
            case HchoLevel.serious: {
                return "cube-red";
            }
            default: {
                return "cube-unknown";
            }
        }
    };
    HchoService.title = function (level) {
        switch (level) {
            case HchoLevel.normal: {
                return "REFERENCE.NORMAL";
            }
            case HchoLevel.over: {
                return "REFERENCE.EXCEEDED";
            }
            case HchoLevel.serious: {
                return "REFERENCE.SERIOUSLY_EXCEEDED";
            }
            default: {
                return "REFERENCE.UNABLE_TO_OBTAIN_DATA";
            }
        }
    };
    return HchoService;
}());
exports.HchoService = HchoService;
var CubeModel = /** @class */ (function (_super) {
    __extends(CubeModel, _super);
    function CubeModel(dict) {
        var _this = _super.call(this, dict) || this;
        //private cube variables
        _this.pm25 = "";
        _this.pm10 = "";
        _this.pm1_0 = "";
        _this.hcho = "";
        _this.battery = "";
        _this.charging = "";
        _this.samplePeriod = "";
        _this.pm25 = dict["pm25"] ? dict["pm25"] : "";
        _this.hcho = dict["hcho"] ? dict["hcho"] : "";
        _this.battery = dict["battery"] ? dict["battery"] : "";
        _this.charging = dict["charging"] ? dict["charging"] : "";
        _this.samplePeriod = dict["samplePeriod"] ? dict["samplePeriod"] : "";
        return _this;
    }
    Object.defineProperty(CubeModel.prototype, "pmLevel", {
        //pm2.5 properties
        get: function () {
            return PmService.level(this.pm25);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "pmBgClass", {
        get: function () {
            if (this.connectStatus == hardware_model_1.ConnectStatus.disconnected) {
                return PmService.offlineClass(this.pmLevel);
            }
            return PmService.bgColorClass(this.pmLevel);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "pmTitle", {
        get: function () {
            return PmService.title(this.pmLevel);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "pmFormated", {
        get: function () {
            var pmInt = parseInt(this.pm25);
            if (isNaN(pmInt) || pmInt < 0) {
                return "--";
            }
            if (pmInt == 0xffff) {
                return "0";
            }
            return pmInt.toFixed();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "hchoLevel", {
        //hcho properties
        get: function () {
            return HchoService.level(this.hcho);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "hchoBgClass", {
        get: function () {
            if (this.connectStatus == hardware_model_1.ConnectStatus.disconnected) {
                return HchoService.offlineClass(this.hchoLevel);
            }
            return HchoService.bgColorClass(this.hchoLevel);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "hchoTitle", {
        get: function () {
            return HchoService.title(this.hchoLevel);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "hchoFormated", {
        get: function () {
            var hchoInt = parseInt(this.hcho);
            if (isNaN(hchoInt) || hchoInt < 0) {
                return "--";
            }
            if (hchoInt == 0xffff) {
                return '0.00';
            }
            return (hchoInt / 1000).toFixed(2);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "batteryLevel", {
        //battery properties
        get: function () {
            return BatteryService.level(this.battery, this.charging);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CubeModel.prototype, "batteryImage", {
        get: function () {
            return BatteryService.image(this.batteryLevel);
        },
        enumerable: true,
        configurable: true
    });
    CubeModel.prototype.setOffline = function () {
        this.status = hardware_model_1.ConnectStatus.disconnected.toString();
        this.charging = "";
    };
    return CubeModel;
}(hardware_model_1.HardwareModel));
exports.CubeModel = CubeModel;
